/*
 * @Author: Wangjun
 * @Date: 2021-05-15 22:46:27
 * @LastEditTime: 2024-07-24 16:10:32
 * @LastEditors: wangjun haodreams@163.com
 * @Description:
 * @FilePath: \godriver\opdb\example\remove\remove.go
 * hnxr
 */
package main

import (
	"log"
	"os"
	"strings"

	"gitee.com/haodreams/godriver/opdb/opsql"
	"gitee.com/haodreams/golib/env"
	"gitee.com/haodreams/golib/logs"
	"gitee.com/haodreams/libs/ee"
	"gorm.io/gorm"
	"gorm.io/gorm/schema"
)

func main() {
	env.Reset()
	data, err := os.ReadFile("conf.txt")
	if err != nil {
		log.Fatalln(err)
	}

	ss := strings.Split(string(data), ";")
	dataSource := strings.TrimSpace(ss[0])

	dialector := opsql.Open(dataSource)
	if dialector == nil {
		ee.NewError("不支持的驱动:" + dataSource).Once2(logs.CbErrorf)
		return
	}
	op, err := gorm.Open(dialector, &gorm.Config{
		NamingStrategy: schema.NamingStrategy{
			SingularTable: true,
		},
	})
	_ = err
	//查询服务器时间
	// tm := int64(0)
	// err = op.Raw("SELECT time").Get(&tm)
	// if err != nil {
	// 	log.Fatalln(err)
	// }
	// log.Println("服务器时间:", tm, time.Unix(tm, 0))

	if len(ss) < 2 {
		log.Fatalln("没有需要发送的数据")
	}

	ss = strings.Split(ss[1], ",")

	op.Exec("REMOVE POINT", ss)

}
